import website.*

class BootStrap {
	def springSecurityService
	
    def init = { servletContext ->
		def guestRole = SecRole.findByAuthority('ROLE_GUEST') ?: new SecRole(authority: 'ROLE_GUEST').save(failOnError: true)
		def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save(failOnError: true)
		
		def adminUser = SecUser.findByUsername('admin') ?: new SecUser(
			username: 'admin',
			password: 'admin',
			enabled: true).save(failOnError: true)
			
		if (!adminUser.authorities.contains(adminRole)) {
				SecUserSecRole.create adminUser, adminRole
		}
		
		def guestUser = SecUser.findByUsername('guest') ?: new SecUser(
			username: 'guest',
			password: 'guest',
			enabled: true).save(failOnError: true)
			
		if (!guestUser.authorities.contains(guestRole)) {
				SecUserSecRole.create guestUser, guestRole
		}
		
    }
    def destroy = {
    }
}
